<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // Promise 是类 
        // 内部有三种状态 Pending(正在进行中) Rejected(失败) Fulfilled(成功)
        // 它们只能由 Pending 转为 Rejected 或 Fulfilled 不能 有 Rejected 或 Fulfilled 转为其他的
        let p = new Promise((resolve, reject) => {
            // resolve 和 reject 是 then 中传入的方法
            setTimeout(() => {
                reject('失败');
                reject('失败');
                resolve('成功');
                return 1;
            }, 2000)
        })

        // 用 then 调用
        let t = p.then((msg) => {
            console.log('successful', msg);
        }, (msg) => {
            console.log('fail', msg);
        })
        console.log(t);
        
    </script>
    
</body>
</html>